package com.example.myapplication.apter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.NewsCarouselmapBean;

import java.util.List;

public class RecommendednewApter extends  RecyclerView.Adapter<RecommendednewApter.Myhot>{
    private Context context;
    private List<NewsCarouselmapBean.RowsBean> list;

    public RecommendednewApter(Context context, List<NewsCarouselmapBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_newrecommendednew,null);
        return new RecommendednewApter.Myhot(view) ;
    }

    @Override
    public void onBindViewHolder(@NonNull Myhot holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getCover()).into(holder.newscomentnews_img);
        holder.newscomentnews_img.setScaleType(ImageView.ScaleType.FIT_XY);
        holder.newscomentnews_text.setText(list.get(position).getTitle());
        holder.newscomentnews_linknum.setText("观看人数:"+list.get(position).getLikeNum());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView newscomentnews_text;
        private final TextView newscomentnews_linknum;
        private final ImageView newscomentnews_img;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            newscomentnews_img = itemView.findViewById(R.id.newscomentnews_img);
            newscomentnews_text = itemView.findViewById(R.id.newscomentnews_text);
            newscomentnews_linknum = itemView.findViewById(R.id.newscomentnews_linknum);
        }
    }
}
